package com.drakulo.hi.gfx.panel;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

import com.dk.hi.core.Settings;
import com.drakulo.hi.gfx.GameViewPort;
import com.drakulo.hi.states.MenuState;

public class MapPanel extends Panel {

	public MapPanel() {
		super.initSize(Settings.WINDOW_WIDTH - MenuState.MENU_WIDTH, Settings.WINDOW_HEIGHT);
	}

	@Override
	public boolean mouseIsOnIt(int mouseX, int mouseY) {
		return false;
	}

	@Override
	public void render(Graphics g) throws SlickException {
		super.render(g);

		TiledMap map = new TiledMap("data/desert.tmx");

		int mapWidth = map.getWidth() * map.getTileWidth();
		// int mapHeigt = map.getHeight() * map.getTileHeight();

		float scale = ((float) (Settings.WINDOW_WIDTH - MenuState.MENU_WIDTH)) / mapWidth;

		g.scale(scale, scale);

		int mod = (int) (MenuState.MENU_WIDTH / scale);
		map.render(mod, 0);

		int playerX = GameViewPort.getPlayerMapX();
		int playerY = GameViewPort.getPlayerMapY();

		g.setColor(Color.red);

		g.drawLine(playerX - 16 + mod, playerY + 16, playerX + 16 + mod, playerY + 16);
		g.drawOval(playerX + mod - 7, playerY + 8, 16, 16);
		g.drawLine(playerX + mod, playerY, playerX + mod, playerY + 32);

		g.scale(1F, 1F);
	}

	@Override
	public void render(Graphics g, int x, int y) throws SlickException {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Input input) {
	}

}
